# K线图页面的右侧第二侧边栏的主力信息
import cv2
import numpy as np
import logging
import pyautogui
import time
from PIL import ImageGrab
from shape_judgment.screen_region_storage import get_region,get_region_pos_only

class right_side_2_main_force:
    def __init__(self,window):
        self.efortune_window = window
        self.template_img_fund_button_active = cv2.imread("eastmoney desktop software picture/right_2_fund_actived.png")
        self.template_img_fund_button_idle = cv2.imread("eastmoney desktop software picture/right_2_fund_idle.png")
        self.template_img_outflow = cv2.imread("eastmoney desktop software picture/right_2_fund_outflow.png")
        self.template_img_small_order = cv2.imread("eastmoney desktop software picture/right_2_fund_small_order.png")
    
    # 屏幕截图
    def capture_window(self):
        try:
            # 获取窗口位置和大小
            x, y = self.efortune_window.left, self.efortune_window.top
            width, height = self.efortune_window.width, self.efortune_window.height
            self.window_pos = (x, y, width, height)
            # 截取窗口区域
            screenshot = ImageGrab.grab(bbox=(x, y, x + width, y + height))
            # 转换为OpenCV格式 (BGR)
            self.frame = cv2.cvtColor(np.array(screenshot), cv2.COLOR_RGB2BGR)            
        except Exception as e:
            logging.error(f"!!!! ERR 36 F10截图时出错: {str(e)}")
            return None
    # 取得右侧边栏第二栏的截图
    def get_right_side_2_clip(self):
        pos_of_region_right_2 = get_region("右侧边栏2") # [x1,x2,y1,y2]
        pos_of_region_right_2_top = get_region("右侧边栏2的顶部按钮区")
        self.pos_of_region_right_2 = pos_of_region_right_2
        self.pos_of_region_right_2_2 = [
            pos_of_region_right_2[0],
            pos_of_region_right_2[1],
            pos_of_region_right_2_top[3],
            pos_of_region_right_2[3]
            ]
        # 截图剪出需要分析的区域
        self.capture_window()
        self.right_side_2_clip = self.frame[pos_of_region_right_2_top[3]:pos_of_region_right_2[3]
                                            , pos_of_region_right_2[0]:pos_of_region_right_2[1]]
        # cv2.imwrite("right_side_2_clip.png", self.right_side_2_clip)
    
    # 找 模板匹配 返回坐标与大小 # 返回(x, y, w, h)
    def find_template_position(self,screen_img, template_img, threshold=0.85):
        """获取所有符合阈值的匹配结果，返回列表[(x, y, w, h, 匹配度)]"""
        # # 预处理（使用之前优化的预处理函数）
        h, w = template_img.shape[:2]
        if h == 0 or w == 0:
            return []
        if screen_img.size < template_img.size:  # 截图尺寸小于模板尺寸
            # print("截图尺寸小于模板尺寸")
            return []
        
        # 执行模板匹配并获取匹配度矩阵
        result = cv2.matchTemplate(
            screen_img, 
            template_img, 
            cv2.TM_CCOEFF_NORMED
        )
        # 找到所有超过阈值的位置
        locations = np.where(result >= threshold)
        all_matches = []
        # 遍历所有匹配位置，记录坐标和匹配度
        for y, x in zip(locations[0], locations[1]):
            match_value = result[y, x]  # 该位置的匹配度（0-1）
            all_matches.append((x, y, w, h, match_value))  # 存储x坐标、y坐标、宽、高、匹配度
        if not all_matches:
            return None  # 无匹配结果
        # 按X坐标升序排序（X越小越靠左），取第一个
        # 若X相同，可选匹配度最高的
        all_matches.sort(key=lambda m: (-m[4]))  # 匹配度倒序排序
        most_matched = all_matches[0]
        return (most_matched[0], most_matched[1], most_matched[2], most_matched[3])  # 返回(x, y, w, h)


    # 鼠标点击 输入的是相对坐标
    def click_button(self,pos_x, pos_y):
        window_pos_x = self.window_pos[0]
        window_pos_y = self.window_pos[1]
        window_width = self.window_pos[2]
        # 移动鼠标到按钮中心
        pyautogui.moveTo(pos_x+window_pos_x, pos_y+window_pos_y, duration=0.0)  # duration控制移动速度，单位秒
        # 点击鼠标左键
        pyautogui.click()
        time.sleep(0.01)
        # 点击后, 把鼠标移到最右, 以防止高亮造成下去的图像比对失败
        pyautogui.moveTo(window_width+window_pos_x, pos_y+window_pos_y, duration=0.0)

    # 保证是激活状态 @return True已激活 False:激活出错
    def guranteed_fund_button_actived(self):
        # 这就没有快捷键了, 只能用鼠标点
        # 先判断已激活, 已激活后就不用点了.
        # self.right_side_2_clip 这个截屏子区域的坐标对应的是 self.pos_of_region_right_2_2 格式是[x1,x2.y1,y2]
        pos_fund_button = self.find_template_position( self.right_side_2_clip ,self.template_img_fund_button_active,.95) # (x, y, w, h)
        
        if pos_fund_button is None:
            pos_fund_button = self.find_template_position( self.right_side_2_clip ,self.template_img_fund_button_idle,.95) # (x, y, w, h)
            if pos_fund_button is None:
                logging.error("!!!! ERR 38 F10_right_side_2_main_force    fund_button_not_found")
                return False
            else:
                # 找到未激活的按钮, 点击
                self.click_button(
                    self.pos_of_region_right_2_2[0]+pos_fund_button[0] + 36, 
                    self.pos_of_region_right_2_2[2]+pos_fund_button[1] + 12) # 确保是按钮的中心点 模板大小是71X24
                # 点击后, 截图判断截出是否正确:
                self.capture_window()
                self.right_side_2_clip = self.frame[self.pos_of_region_right_2_2[2]:self.pos_of_region_right_2_2[3]
                                                    , self.pos_of_region_right_2_2[0]:self.pos_of_region_right_2_2[1]]
                pos_fund_button = self.find_template_position( self.right_side_2_clip ,self.template_img_fund_button_active,.95)
                if pos_fund_button is None:
                    return False # 等下一轮回吧 下一个大轮回, 会重新进入点击流程 正好等左侧图表区加载
                else:
                    return True
        else:
            # 已经是激活状态, 不用再点击了.
            return True

    # 切出柱状图表:
    def cut_out_bar_chart(self):
        # self.right_side_2_clip 这个截屏子区域的坐标对应的是 self.pos_of_region_right_2_2 格式是[x1,x2.y1,y2]

        pos_outflow = self.find_template_position( self.right_side_2_clip ,self.template_img_outflow,.95) # 返回(x, y, w, h)
        pos_small_order = self.find_template_position( self.right_side_2_clip ,self.template_img_small_order,.95) # 返回(x, y, w, h)
        inner_cut_pos =  [0,self.pos_of_region_right_2_2[1]-self.pos_of_region_right_2_2[0],pos_outflow[1]+pos_outflow[3],pos_small_order[1]] # [x1,x2,y1,y2]
        print(f"# 132 right_side_2_main_force    cut_out_bar_chart    inner_cut_pos:{inner_cut_pos}")
        self.right_side_2_bar_chart = self.right_side_2_clip[inner_cut_pos[2]:inner_cut_pos[3]
                                                            , inner_cut_pos[0]:inner_cut_pos[1]]
        raw_img_h,raw_img_w = self.right_side_2_bar_chart.shape[:2]
        # cv2.imwrite(f"right_side_2_main_force_[inner_chart_2_bar_chart].png", self.right_side_2_bar_chart)
        # 至此 self.right_side_2_bar_chart 是两个小表格, 数字表格与柱状图. 其中柱状图这里大概率是空的, 这里的下一步只需要截出区域, 是不是空后需要往后一步再判断 应该不会在这个函数里判断
        # 如果分两步, 从前开始遍历, 再从后开始遍历, 可节省很多时间
        # 如果从底部往上遍历, 能节省很多时间
        # BEGIN 遍历图表, 找可行的像素点
        # 左侧边界
        left_x = 0
        left_y = 0
        for x in range(1,raw_img_w):
            y = raw_img_h-1 # 从下往上遍历
            b,g,r = self.right_side_2_bar_chart[y,x]
            if (60,60,60) == (b,g,r): 
                left_x = x # 存左侧X
                # 遍历Y
                y-=1
                while y > 0:
                    b,g,r = self.right_side_2_bar_chart[y,x]
                    if (60,60,60) != (b,g,r):
                        left_y = y+2
                        break
                    y-=1
                break
        if 0 == left_y:
            raise Exception("ERR 158 F10_right_side_2_main_force    0 == left_y")
        # 右侧边界:
        right_x = raw_img_w-1
        right_y = 0
        x = raw_img_w-2
        while x >= left_x:
            y = raw_img_h-1
            (b,g,r) = self.right_side_2_bar_chart[y,x]
            if (60,60,60) == (b,g,r): 
                right_x = x
                # y-=1 # 上面的left_y与right_y是一致的
                # while y > 0:
                #     (b,g,r) = self.right_side_2_bar_chart[y,x]
                #     if (60,60,60) != (b,g,r):
                #         right_y = y+2
                #         break
                #     y-=1
                break
            x-=1
        self.bar_chart = self.right_side_2_bar_chart[ left_y:raw_img_h ,left_x+1:right_x ]
        cv2.imwrite(f"right_side_2_main_force_[bar_chart].png", self.bar_chart) # 柱状图

    # 处理图片,去除黑边
    def format_the_image_remove_black(self,img):
        height,width = img.shape[:2]
        img_resul1 = None # 去除上也黑边的结果
        # 去除上下黑边
        new_top = 0
        new_buttom = height
        for y in range(height):
            is_hole_line_black = True
            for x in range(width):
                color = img[y,x]
                if 7 < color[0]:
                    is_hole_line_black = False
                    break
            if is_hole_line_black:
                new_top = y+1
            else:
                break
        y = height-1
        while y>0:
            is_hole_line_black = True
            for x in range(width):
                color = img[y,x]
                if 7 < color[0]:
                    is_hole_line_black = False
                    break
            if is_hole_line_black:
                new_buttom = y
            else:
                break            
            y-=1
        img_resul1 = img[new_top:new_buttom,:]
        # 去除左右黑边
        new_left = 0
        new_right = width
        for x in range(width):
            is_hole_column_black = True
            for y in range(0,new_buttom-new_top):
                color = img_resul1[y,x]
                if 7 < color[0]:
                    is_hole_column_black = False
                    break
            if is_hole_column_black:
                new_left = x+1
            else:
                break
        for x in range(width-1,-1,-1):
            is_hole_column_black = True
            for y in range(0,new_buttom-new_top):
                color = img_resul1[y,x]
                if 7 < color[0]:
                    is_hole_column_black = False
                    break
            if is_hole_column_black:
                new_right = x
            else:
                break
        return img_resul1[:,new_left:new_right]


    def get_number_from_image_10h(self,img):
        height,width = img.shape[:2]
        result_str = "" 
        x = 0 # 从头开始遍历
        while x < width:
            # #0
            b,g,r = img[0,x]
            if 7 < g:# 5 7
                b_1,g_1,r_1 = img[1,x]
                if 7 < g_1:
                    result_str+="5"
                else:
                    result_str+="7"
                x+=8 # 跳过字符宽度6像素以及两空行
                continue
            # #1
            b,g,r = img[1,x]
            if 7 < g:# 0 1 2 3 6 8 9
                g_2,b_2,r_2 = img[2,x]
                if 7 < g_2:# 0 2 6 8 9
                    '''
                    0:1 2 3 4 5 6 7 8
                    2:1 2         7 8 9
                    6:1 2 3 4 5 6 7 8  往后的第三列:4这个位置有颜色
                    8:1 2 3   5
                    9:1 2 3 4       8 
                    '''
                    b_3,g_3,r_3 = img[3,x]
                    if 7 < b_3:# 0 6 8 9
                        '''
                        0:1 2 3 4 5 6 7 8
                        6:1 2 3 4 5 6 7 8  往后的第三列:4这个位置有颜色
                        8:1 2 3   5
                        9:1 2 3 4       8 
                        '''
                        b_4,g_4,r_4 = img[4,x]
                        if 7 < b_4:# 0 6 9
                            '''
                            0:1 2 3 4 5 6 7 8
                            6:1 2 3 4 5 6 7 8  往后的第三列:4这个位置有颜色
                            9:1 2 3 4       8 
                            '''
                            b_5,g_5,r_5 = img[5,x]
                            if 7 < b_5:# 0 6
                                '''
                                0:1 2 3 4 5 6 7 8
                                9:1 2 3 4       8 
                                ''' 
                                b_43,g_43,r_43 = img[4,x+2]
                                if 7 < b_43:
                                    result_str+="6"
                                else:# 6
                                    result_str+="0"                                
                            else:# 0
                                result_str+="9"
                        else:# 6
                            result_str+="8"
                    else:# 2
                        result_str+="2"
                else: # 1 3
                    g_8,b_8,r_8 = img[8,x]
                    if 7 < g_8:
                        result_str+="3"
                    else:
                        result_str+="1"
                x+=8 # 跳过字符宽度6像素以及两空行
                continue
            
            # #5
            b_5,g_5,r_5 = img[5,x]
            if 7 < b_5: # -
                result_str+="-"
                x+=5 # 负号宽四像素,后面空一列
                continue
            # #6
            b_6,g_6,r_6 = img[6,x]
            if 7 < b_6: # 4
                result_str+="4"
                x+=8 # 跳过字符宽度6像素以及两空行
                continue
            else: # 0
                cv2.imwrite("right_side_2_ERR_322_10h.png",img)
                raise Exception(f"找不到匹配的数字")
        return result_str
    
    def get_number_from_image_8h(self,img):
        height,width = img.shape[:2]
        result_str = "" 
        x = 0 # 从头开始遍历
        while x < width:
            # #0
            b,g,r = img[0,x]
            if 7 < g:# 5 7
                b_1,g_1,r_1 = img[1,x]
                if 7 < g_1:
                    result_str+="5"
                else:
                    if 0 == x:
                        result_str+="7"
                        x+=5 # 第1个数字是7,这是特殊情况
                        continue
                    else:
                        cv2.imwrite(f"right_side_2_ERR_340_8h_{x}.png",img)
                        raise Exception(f"!!!!    ERR 340 找不到匹配的数字  if 7 < g:# 5  x={x}")
                x+=6 # 跳过字符宽度5像素以及1空行
                continue
            # #1
            b,g,r = img[1,x]
            if 7 < g:# 0 1 2 3 8 9
                b_2,g_2,r_2 = img[2,x]
                if 0 == x: # 0 1 2 3 8 9
                    '''
                    0:1 2 3 4 5 6
                    1:1           7
                    2:1 2       6 7
                    3:1         6
                    8:1 2   4 5 6 
                    9:1 2 3 
                    '''
                    if 7 < g_2:# 0 2 8 9
                        '''
                        0:1 2 3 4 5 6
                        2:1 2       6 7
                        8:1 2   4 5 6 
                        9:1 2 3 
                        '''
                        b_3,g_3,r_3 = img[3,x]
                        b_4,g_4,r_4 = img[4,x]
                        if 7 < b_3:# 0 9
                            if 7 < b_4:
                                result_str+="0"
                            else:
                                result_str+="9"
                        else:# 2 8
                            '''
                            2:1 2       6 7
                            8:1 2   4 5 6 
                            '''
                            if 7 < b_4:
                                result_str+="8"
                            else:
                                result_str+="2"
                    else: # 1 3
                        b_6,g_6,r_6 = img[6,x]
                        if 7 < b_6: # 1
                            result_str+="3"
                        else: # 3
                            result_str+="1"
                            x+=5
                            continue # 第一个数字是1 这是特殊情况
                    x+=6 # 跳过字符宽度5像素以及1空行
                    continue
                else:
                    '''
                    0:1 2 3 4 5 6
                    2:1 2       6 7
                    3:1         6
                    8:1 2   4 5 6 
                    9:1 2 3 
                    '''
                    if 7 < g_2:# 0 2 8 9
                        '''
                        0:1 2 3 4 5 6
                        2:1 2       6 7
                        8:1 2   4 5 6 
                        9:1 2 3 
                        '''
                        b_3,g_3,r_3 = img[3,x]
                        b_4,g_4,r_4 = img[4,x]
                        if 7 < b_3:# 0 9
                            if 7 < b_4:
                                result_str+="0"
                            else:
                                result_str+="9"
                        else:# 2 8
                            '''
                            2:1 2       6 7
                            8:1 2   4 5 6 
                            '''
                            if 7 < b_4:
                                result_str+="8"
                            else:
                                result_str+="2"
                    else: # 3
                        result_str+="3"
                    x+=6 # 跳过字符宽度5像素以及1空行
                    continue
            # #2
            b_2,g_2,r_2 = img[2,x]
            if 7 < b_2: # 4
                result_str+="6"
                x+=6 # 跳过字符宽度5像素以及1空行
                continue

            # #3
            b_3,g_3,r_3 = img[3,x]
            if 7 < b_3: # -
                result_str+="-"
                x+=6 # 负号宽四像素,后面没空列
                continue

            # #4
            b_4,g_4,r_4 = img[4,x]
            if 7 < b_4: # 4
                result_str+="4"
                x+=6 # 跳过字符宽度5像素以及1空行
                continue
            else: # 1 7
                b_10,g_10,r_10 = img[0,x+1]
                if 7 < b_10: # 1
                    result_str+="7"
                else: # 7
                    result_str+="1"
                x+=6 # 跳过字符宽度5像素以及1空行
                continue

        return result_str


    # 分析柱状图的数字 就怕数字的大小不一致 是的, 不一致
    def get_number_from_image(self,img):
        height,width = img.shape[:2]
        if 10 == height:
            return self.get_number_from_image_10h(img)
        elif 8 == height:
            return self.get_number_from_image_8h(img)


    # 连续16像素横放, 一定是柱状图 ; y下标为48, 必然是分隔线
    def get_bar_chart_numbers(self):
        # 下标y为47与49, 必然是柱状图的位置, 不会是数字, 数字与分隔线有三像素的距离
        # 有柱状图的区块, 就一定有对应的数字. 一般是四个, 可能是三个
        # 先找到柱状图, 然后柱状图对过去, 从两边找数字的所有像素点

        # 扫描y=47这一个, 记录所有柱状图的中间点
        # 扫描y=49, 找到柱状图,记录其中间点
        center_x_of_bar = [] # 必须存y值是47还是49, 不然找不到找数字的方向 # 红绿两边整到一个循环内, 就不用之后再排序
        x = 0
        while x < self.bar_chart.shape[1]:
            for y in [47,49]:
                pixel_color = self.bar_chart[y,x]
                if 7 < pixel_color[0]:
                    center_x_of_bar.append((x+8,y)) # bar的宽是16
                    x+=17 # 快进到下一个柱子
            x+=1
                
        print(f"# 204 柱状图x前后位置:{center_x_of_bar}") # 输出: [(24, 49), (74, 47), (124, 49), (174, 49)]

        # if 3 == len(center_x_of_bar):
        #     print(f"# 207 只有3个柱") # 这里面还有三种情况, 缺了哪个柱不知道


        # 根据柱状图的位置, 找数字的像素点:
        imgs_number = []
        for point in center_x_of_bar:
            x,y = point
            field_name = ""
            if 24 == x:
                field_name = "超大"
            elif 74 == x:
                field_name = "大单"
            elif 124 == x:
                field_name = "中单"
            elif 174 == x:
                field_name = "小单"
            else:
                cv2.imwrite(f"right_side_2_ERR_279.png",self.bar_chart)
                raise Exception(f"!!!!    ERR 279 图表中x位置:{x}没有对应的字段名 是不是窗口没缩小 窗口应该缩到侧边栏大小不动 已输出right_side_2_ERR_279.png 图表宽:{self.bar_chart.shape[1]}")

            if y == 47:
                y_another = 49
                x_backward = x-1 
                x_forward = x+1
                empty_times = 0 # 连空四个可能是数字1的前后,两个1 在一起, 也是连空4个格子, 连空5个格子就不是数字区. 实际上, 远处连续空出的格子数能达31. 最少也空6个格子
                while x_backward >= 0 and x_forward<self.bar_chart.shape[1]:
                    # (b,g,r) = self.bar_chart[y_another,x_backward]
                    y_find = y_another+2
                    # bool_is_done = False # 已输出图像, 就不要执行下去
                    y_end = y_find+12
                    bool_empty = True
                    while y_find <= y_end:
                        for x_find in [x_backward,x_forward]:
                            (b,g,r) = self.bar_chart[y_find,x_find]
                            if 7 < b:
                                bool_empty = False
                                break
                        y_find+=1
                    if bool_empty:
                        empty_times+=1
                    else:
                        empty_times = 0
                    if empty_times > 4 or (1 == x_backward and empty_times > 0) or (self.bar_chart.shape[0]-2 == x_forward and empty_times > 0): # 连续空5个格子, 确定不是数字
                        img_number = self.bar_chart[y_another+2:y_end,x_backward:x_forward]
                        # cv2.imwrite(f"right_side_2_main_force_[number_{point[0]}_{point[1]}].png", img_number)
                        imgs_number.append((field_name,self.format_the_image_remove_black(img_number)))
                        # # bool_is_done = True
                        # print(f"# 233 输出图像")
                        break
                    # else:
                    #     print(f"# 235 空列数:{empty_times}")
                    # if bool_is_done:
                    #     break
                    x_backward-=1
                    x_forward+=1
                # END while
            else:
                y_another = 47
                x_backward = x-1 
                x_forward = x+1
                empty_times = 0 # 连空四个可能是数字1的前后,两个1 在一起, 也是连空4个格子, 连空5个格子就不是数字区. 实际上, 远处连续空出的格子数能达31. 最少也空6个格子
                while x_backward >= 0 and x_forward<self.bar_chart.shape[1]:
                    # (b,g,r) = self.bar_chart[y_another,x_backward]
                    y_find = y_another-2
                    # bool_is_done = False # 已输出图像, 就不要执行下去
                    y_end = y_find-12
                    bool_empty = True
                    while y_find > y_end:
                        for x_find in [x_backward,x_forward]:
                            (b,g,r) = self.bar_chart[y_find,x_find]
                            if 7 < b:
                                bool_empty = False
                                break
                        y_find-=1
                    if bool_empty:
                        empty_times+=1
                    else:
                        empty_times = 0
                    if empty_times > 4 or (1 == x_backward and empty_times > 0) or (self.bar_chart.shape[0]-2 == x_forward and empty_times > 0): # 连续空5个格子, 确定不是数字
                        img_number = self.bar_chart[y_end:y_another-2,x_backward:x_forward]
                        # cv2.imwrite(f"right_side_2_main_force_[number_{point[0]}_{point[1]}].png", img_number)
                        # cv2.imwrite(f"right_side_2_main_force_[number_{point[0]}_{point[1]}]_2.png", self.format_the_image_remove_black(img_number))
                        imgs_number.append((field_name,self.format_the_image_remove_black(img_number)))
                        # # bool_is_done = True
                        # print(f"# 233 输出图像")
                        break
                    # else:
                    #     print(f"# 235 空列数:{empty_times}")
                    # if bool_is_done:
                    #     break
                    x_backward-=1
                    x_forward+=1
                # END while

        print(f"# 355 切出图片数目:{len(imgs_number)}")

        result_field_number = []
        for img_set in imgs_number:
            field_str = img_set[0]
            img = img_set[1]
            number_str = self.get_number_from_image(img)
            result_field_number.append((field_str,number_str))
        
        result_field_number_formated = [] 
        # 判断哪有缺, 缺的补0
        field_list = ["超大","大单","中单","小单"]
        for field_name in field_list:
            number_str = "0"
            for data_1 in result_field_number:
                field_name_1 = data_1[0]
                number_str_1 = data_1[1]
                if field_name_1 == field_name:
                    number_str = number_str_1
                    break
            result_field_number_formated.append((field_name,number_str))

        return result_field_number_formated
        raise Exception(f"####    正在开发    #### {result_field_number_formated}")
        return result_field_number


    # 取数据:
    def get(self):
        logging.info("# 38 main_force get begin")
        self.get_right_side_2_clip() # 取得右侧边栏第二栏的截图
        bool_result_fund_button_state = self.guranteed_fund_button_actived() # 保证是激活状态 
        if False == bool_result_fund_button_state: # 激活失败
            logging.info("# 188 main_force get END")
            return None
        self.cut_out_bar_chart() # 得到无边框的柱状图 self.bar_chart
        result_numbers = self.get_bar_chart_numbers()
            
        logging.info("# 193 main_force get END")
        return result_numbers
        return None




'''

10像素高:
-:5 横向4像素 后面有一空列
0:1 2 3 4 5 6 7 8 往后的第三列:4这个位置为空	(宽度为6,后面空两列)
1:1 
2:1 2   7 8 9
3:1 8
4:6 7 
5:0 1 2 3 4 5   8
6:1 2 3 4 5 6 7 8 往后的第三列:4这个位置有颜色
7:0 
8:1 2 3   5
9:1 2 3 4   8 
遍历y值:0,1,5,6 (如果一开始就去掉负号, 那么5这个位置不需要遍历, 有遍历的话, 能与红色的文字共用)
所有的数字宽度为6 负号除外
后面都空两列 负号除外


8像素高:
-:3 横向6像素 后面冇空列
0:1 2 3 4 5 6
1:1 7
2:1 2   6 7
3:1 6
4:4 5
5:0 1 2 3 4   6
6:2 3 4 5 6
7:0 
8:1 2   4 5 6 
9:1 2 3 
遍历y值:0,1,3,4
负号后面没有空列除外, 一般数字后面空1列 , 1这个数字是例外, 1的宽度是3,后面空两列, 一般数字的宽度是5,后面空1列
当负号后面是1时, 空1列, 也就是1也是可以当作5宽度,然后与其它数字一样空一列
7这个数字,也跟1一样宽度比其它数字小,也算是第一列就是空列


'''